package view;

import java.awt.Color;

import javax.swing.JTextField;
import javax.swing.event.DocumentListener;
/**
 * An {@code AlphaTextField} is a {@code JTextField} to handle alpha-numeric
 * inputs.
 * @author Oliver Eckstein
 *
 */
public class AlphaTextField extends JTextField {
	
	private static final long serialVersionUID = 1L;
    
	/**
	 * To indicate if this text fields shows an error. 
	 */
    private boolean showsError;
    
    /**
     * This is the ID of the parameter or abstract process etc. that gets
     * connected to this text field.
     */
    private String parameterID;
    
    /**
     * To create a new {@code JTextField} with a given {@code length}.
     * @param length length of the text field.
     */
    public AlphaTextField(String parameterID) {
        super(15);
        showsError = false;
        this.parameterID = parameterID;                
    }
    
    /**
     * Indicates that the input caused an error.
     */
    public void showError()
    {
        setBackground(Color.RED);        
        showsError = true;
    }
    
    /**
     * Removes the error indication.
     */
    public void clearError()
    {
        setBackground(Color.WHITE);
        showsError = false;
    }
    
    /**
     * To get the actual error status of this {@code NumericalTextField}.
     * @return error status
     */
    public boolean getErrorStatus()
    {
        return showsError;
    }
    
    /**
     * To add a {@code DocumentListener} to this {@code NumericalTextField}.
     * @param theController the controller which controls this
     *  {@code NumericalTextField}. 
     */
    public void addDocumentListener(DocumentListener theController)
    {
        getDocument().addDocumentListener(theController);
    }
    
    /**
     * To get the ID of the connected model instance that gets connected
     * to this text field.
     * @return the ID.
     */
    public String getParameterID() {
    	return parameterID;
    }
}
